package logic

import (
	"context"
	"gorm.io/gorm"
	"work_srv/models"

	"work_srv/internal/svc"
	"work_srv/work"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePasswordLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdatePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePasswordLogic {
	return &UpdatePasswordLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdatePasswordLogic) UpdatePassword(in *work.UpdatePasswordRequest) (*work.UpdatePasswordResponse, error) {
	// todo: add your logic here and delete this line
	users := models.User{
		Model: gorm.Model{
			ID: uint(in.UserId),
		},
		Phone:    in.Phone,
		Password: in.Password,
	}
	models.DB.Updates(&users)
	return &work.UpdatePasswordResponse{
		Id: int64(users.ID),
	}, nil
}
